﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using KMF.Common;

namespace KMF.DAL
{
    public partial class NewsDb
    {
        public static List<NewsListAdminDto> GetAllNewsListAdmin_Pagging(int page, int itemsPerPage, ref int totalPage, ref int totalRecord)
        {
            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSPX_Admin_News_GetAllParent_Paging");
            try
            {
                command.Parameters.Add(dao.CreateParameter("@Page", page));
                command.Parameters.Add(dao.CreateParameter("@ItemsPerPage", itemsPerPage));
                SqlParameter itemTotalPage = command.Parameters.Add("@TotalPage", SqlDbType.Int);
                itemTotalPage.Direction = ParameterDirection.Output;
                SqlParameter itemTotalRecord = command.Parameters.Add("@TotalRecord", SqlDbType.Int);
                itemTotalRecord.Direction = ParameterDirection.Output;
                var result = dao.GetDTOList<NewsListAdminDto>(ref command);
                totalPage = int.Parse(itemTotalPage.Value.ToString() == "" ? "0" : itemTotalPage.Value.ToString());
                totalRecord = int.Parse(itemTotalRecord.Value.ToString() == "" ? "0" : itemTotalRecord.Value.ToString());

                return result;
            }
            finally
            {
                command.Connection.Close();
            }
        }
    }
}
